#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
class Solution
{
public:
    int largestAltitude(vector<int> &gain)
    {
        int n = gain.size();
        vector<int> tower(n + 1, 0);
        int max_gain = 0;
        for (int i = 1; i < n + 1; i++)
        {
            tower[i] = gain[i - 1] + tower[i - 1];
            cout << tower[i] << " ";
            max_gain = max(tower[i], max_gain);
        }
        // return max_element(tower.begin(),tower.end());
        return max_gain;
    }

    int largestAltitude_1(vector<int> &gain)
    {
        int ans = 0, sum = 0;
        for (int x : gain)
        {
            sum += x;
            ans = max(ans, sum);
        }
        return ans;
    }
};
int main()
{
    Solution s;
    vector<int> gain = {-5, 1, 5, 0, -7};
    cout << s.largestAltitude(gain) << endl;
    system("pause");
    return 0;
}
